The Progress Bar application demonstrates the versatility of the inbuilt controls supplied with Crimson Basic. It simulates a Progress Bar by dynamically changing a Rectangle's properties at run time in response to user events.
PBDemo Form
The form comprises a containing Rectangle (drawn in Red), the Progress Bar Rectangle (drawn in Blue) and 2 buttons.
The form is initially invisible and has a Close Box.
Initial program module
The Initial module declares a Global variable named BarPosition which holds the size of the Progress Bar expressed as a percentage of the width of the containing Rectangle.
This is initially set to zero, the form opened, the Progress Bar initially drawn (as zero width) and the form made visible using the ShowWindow Method.
PBDemoMain program module
For each of the buttons, both the Click and DoubleClick events are trapped. It is wise to do this in this type of application as the buttons are likely to be pressed rapidly and this will be interpreted as a double click.
When the DecButton is clicked, the BarPosition variable is decremented by 10 (%) and the Progress Bar redrawn.
When the IncButton is clicked, the BarPosition variable is incremented by 10 (%) and the Progress Bar redrawn.
The PBDemo.OnClose event is called whenever the user clicks on the Close Box on the form. In this case the form is close and the application ended.
The Draw_Bar procedure first calculates how wide the containing rectangle is by reading the rectangles Width property, which is expressed in pixels, and then subtracting 2 from this (for the lines on the right hand and left hand side).
The new width of the Progress Bar is then calculated as a percentage of the width of the containing rectangle.
Finally the new width of the Progress bar is set with the statement 'PBDemo.Bar.Width=BarWidth'.
Most control properties can be changed at run time. See the separate document entitled 'Properties, Methods and Events' for more details.